﻿using DH.Core.Helper;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Text;

namespace DH.Web.Helper
{
   public static  class SessionHelper
    {

        public static  void SetSession(this HttpContext httpContext,string key, object value)
        {
            httpContext.Session.Set(key, ByteConvertHelper.Object2Bytes(value));            
        }
        public static T GetSession<T>(this HttpContext httpContext,string key) where T:class
        {
            byte[] result;
            httpContext.Session.TryGetValue("key", out result);
            if (result!=null)
            {
                var resObj = ByteConvertHelper.Bytes2Object<T>(result);
                return resObj;
            }
            else
            {
                return null;
            }
            
        }
        public static void RemoveSession(this HttpContext httpContext,string key)
        {
            httpContext.Session.Remove(key);            
        }
    }
}
